<template>
  <div>
    <!-- 容器 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :class="isCollapse ? 's' : 'w'">
        <div class="logo" v-show="!isCollapse"></div>
        <div class="logo" v-show="isCollapse"></div>
        <el-menu
          :default-active="editableTabsValue"
          class="el-menu-vertical-demo"
          @select="handleOpen"
          @open="handleOpen"
          @close="handleClose"
          background-color="#576574"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse"
        >
          <!-- 菜单项 -->
          <el-menu-item index="1" @click="ck(1, '首页')">
            <i class="el-icon-house"></i>
            <span>首页</span>
          </el-menu-item>
          <el-menu-item index="2" @click="ck(2, '商品管理')">
            <i class="el-icon-document"></i>
            <span slot="title">商品管理</span>
          </el-menu-item>
          <el-menu-item index="3" @click="ck(3, '用户管理')">
            <i class="el-icon-setting"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>其他</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="4" @click="ck(4, '页面1')"
                >页面1</el-menu-item
              >
              <el-menu-item index="5" @click="ck(5, '页面2')"
                >页面2</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容区域 -->
      <el-container>
        <el-header>
          <el-menu
            :default-active="tabIndex"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
          >
            <div class="menu-icon" @click="isCollapse1">
              <i class="el-icon-menu"></i>
            </div>
            
            <!-- 面包屑导航 -->
            <el-breadcrumb separator="/"
              style="position: absolute; margin-left: 100px; margin-top: 25px"
            >
              <el-breadcrumb-item
                v-for="(shu1, index1) in shu"
                :key="index1"
                :class="{ SHU1: tabIndex === String(index1 + 1) }"
                ><span @click="ck1(String(index1 + 1), String(shu1))">
                  {{ shu1 }}</span
                ></el-breadcrumb-item
              >
            

            </el-breadcrumb>
            <!-- 右侧菜单 -->
            <!-- <slot name="time" style="color: black;"></slot> -->

            <div class="time-slot" style="color: black; margin-top:10px"></div>
            <span
              style="float: right; width: 100px height: 50px; margin-left: 100px;"
            >
            
              <img
                @click="qiehuan"
                style="
                  position: absolute;
                  left: 1354px;
                  width: 50px;
                  height: 50px;
                  margin-top: -45px;
                "
                src="./zizujian/time.png"
                alt=""
              />
            

              <div
                style="
                  position: absolute;
                  margin-top: 0px;
                  display: flex;
                  flex-wrap: wrap;
                  left: 1320px;
                "
                v-show="qiehuan1"
              >
                <div
                  style="
                    margin-left: 70px;
                    width: 0;
                    height: 0;
                    border-left: 5px solid transparent;
                    border-right: 5px solid transparent;
                    border-bottom: 10px solid #fff;
                  "
                ></div>
                <div style="width: 100px; height: 70px; background-color: #fff">
                  <!-- 个人中心和退出登录 -->
                  <div
                    style="
                      width: 100px;
                      height: 30px;
                      line-height: 30px;
                      margin-top: 5px;
                    "
                    class="jianbuian"
                    @click="ck(1, '首页'), (qiehuan1 = false)"
                  >
                    首页
                  </div>
                  <div
                    style="width: 100px; height: 30px; line-height: 30px"
                    class="jianbuian"
                    @click="ck('denglu')"
                  >
                    退出登录
                  </div>
                </div>
              </div>
            </span>
          </el-menu>
        </el-header>

        <!-- 主体内容区域 -->
        <el-main>
          <el-tag
            v-for="(item, index) in shu"
            :key="index"
            closable
            type=""
            :effect="effecttagName == item ? 'dark' : 'plain'"
            :disable-transitions="false"
            @click="tabclick(item, index)"
            @close="handleClose(item, index)"
          >
            {{ item }}
          </el-tag>
          <!-- 路由视图 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import sj from '/脚手架/test/src/课件/yonghu/zizujian/sj.vue'
export default {
  
  data() {
    return {
      effecttagName: "",
      shu: ["首页"],
      ysd: "",
      cloSable: -1,
      Hshu: ["首页", "商品管理", "用户管理", "页面1", "页面2"],
      isCollapse: true,
      qiehuan1: false,
      editableTabsValue: "1", // 当前激活的标签页名字
      tabIndex: "1",
      SHUshu: 0,
      //记录
      // jl:'1',
    };
    
  },
  
  created() {
    // console.log(document.title);
    this.effecttagName =
      document.title == 1
        ? "首页"
        : document.title == 2
        ? "商品管理"
        : document.title == 3
        ? "用户管理"
        : document.title == 4
        ? "页面1"
        : document.title == 5
        ? "页面2"
        : "";
  },
  computed: {},
  beforeRouteEnter(to, from, next) {
    if (JSON.parse(localStorage.getItem("vuex")).bool) {
      next();
    } else {
      next(false);
    }
  },
  mounted() {
    let shu1 = Number(this.$store.state.editableTabsValue);
    let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
    this.ck(this.$store.state.editableTabsValue, shu[shu1 - 1]);
    setInterval(() => {
    const now = new Date();
    const hours = now.getHours();
    const minutes = now.getMinutes();
    const seconds = now.getSeconds();
    const timeSlot = document.querySelector('.time-slot');
    timeSlot.textContent = `${hours}:${minutes}:${seconds}  `;
  }, 1000);
  },

  methods: {
    removeTab(tab) {
      const index = this.editableTabs.findIndex(
        (item) => item.name === tab.name
      );
      this.editableTabs.splice(index, 1);
      if (this.editableTabsValue === tab.name) {
        this.$router.push(nextTab.path);
        const len = this.editableTabs.length;
        const nextTab = this.editableTabs[len - 1];
        this.editableTabsValue = nextTab.name;
      }
    },
    qiehuan() {
      this.qiehuan1 = !this.qiehuan1;
    },
    ckx(e) {
      if (e != 0) {
        this.shu.splice(e, 1);
        if (this.SHUshu >= e) {
          this.SHUshu -= 1;
          this.tabIndex = (this.SHUshu + 1).toString();
          let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
          this.editableTabsValue = (
            shu.indexOf(this.shu[this.tabIndex - 1]) + 1
          ).toString();
          this.$router.push({ name: this.editableTabsValue });
        }
      }
    },

    SHU1(e) {
      let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
      this.tabIndex = (this.shu.indexOf(this.shu[e]) + 1).toString();
      this.editableTabsValue = (shu.indexOf(this.shu[e]) + 1).toString();
      this.$router.push({ name: this.editableTabsValue });
      this.SHUshu = e;
    },
    yiru(e) {
      if (e == -1) {
        this.cloSable = e;
      } else {
        this.cloSable = e;
      }
    },
    isCollapse1() {
      this.isCollapse = !this.isCollapse;
    },
    handleSelect(key, keyPath) {},
    ck(e, l) {
      if (e == "denglu") {
        this.$store.commit("akk", false);
      }
      if (!this.shu.includes(l)) {
        this.shu.push(l);
      }
      if (!isNaN(e)) {
        this.ysd = this.shu.indexOf(l).toString();
        this.tabclick(l, this.ysd);
        this.editableTabsValue = `${e}`;
        this.SHUshu = this.shu.indexOf(l);

        this.$store.commit("arc", this.editableTabsValue);
      }
      this.$router.push({ name: e });
    },
    handleOpen(key, keyPath) {},
    // handleClose(key, keyPath) {},
    tabclick(e, k) {
      let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
      // console.log('ysd');
      // console.log(e, "e");
      // console.log(k, "k");
      // console.log();
      this.editableTabsValue = (shu.indexOf(e) + 1).toString();
      this.effecttagName = e;
      this.$router.push({
        name:
          e == "首页"
            ? "1"
            : e == "商品管理"
            ? "2"
            : e == "用户管理"
            ? "3"
            : e == "页面1"
            ? "4"
            : e == "页面2"
            ? "5"
            : "",
        params: {
          title:
            e == "首页"
              ? "1"
              : e == "商品管理"
              ? "2"
              : e == "用户管理"
              ? "3"
              : e == "页面1"
              ? "4"
              : e == "页面2"
              ? "5"
              : "",
        },
      });
      this.$router.afterEach((to, from) => {
        document.title = to.params.title;
      });
      // console.log();
      // console.log(this.editableTabsValue);
    },
    // 小标签删除
    handleClose(tag) {
      // console.log(tag);
      this.shu.splice(this.shu.indexOf(tag), 1);
    },

    removeTab(targetName) {
      // console.log(targetName, "targetName");
      let tabs = this.shu;
      this.ysd = targetName;
      // console.log(this.editableTabsValue);
      let activeName = this.editableTabsValue;
      // console.log(this.shu[targetName]);
      this.shu = this.shu.filter((item) => item != this.shu[targetName]);
    },

    ck1(e, l) {
      let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
      this.editableTabsValue = (shu.indexOf(l) + 1).toString();
      this.tabIndex = (this.shu.indexOf(l) + 1).toString();
      this.SHUshu = e - 1;
      this.tabclick(l, e);
      this.$router.push({ name: this.editableTabsValue });
    },
  },
};
</script>

<style lang='less' scoped>
/deep/.el-tabs--border-card > .el-tabs__content {
  padding: 0px !important;
}

.jianbuian:hover {
  background-color: #40a0ff82;
  color: #409eff;
}

.SHU {
  background-color: #409eff;
  color: #fff;
}

.SHU1 {
  // outline: 1px solid #409eff;
  background-color: #fff;
  color: #409eff;
}

.SHU1:hover {
  background-color: #409eff;
  color: #fff;
}

.logo {
  color: #fff;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
}

/deep/.el-tabs__item {
  height: 25px !important;
  line-height: 20px !important;
  text-align: center;
}

.w {
  width: 200px !important;
}

.s {
  width: 60px !important;
}

/deep/.el-menu {
  border: none;
  background-color: #ffffff !important;
}

.el-header {
  .el-menu-item.is-active {
    color: #0a76e2 !important;
  }

  background-color: #fff;
  color: #00ff48;
  text-align: center;
  line-height: 40px;
  height: 60px;
}

/deep/.el-aside {
  ul {
    text-align: left;
    background-color: #576574 !important ;
  }
  background-color: #576574 !important ;
  color: #e9eef3;
  text-align: center;
}

/deep/.el-menu-item.is-active {
  color: #00ef28 !important;
}

.el-menu--horizontal > .el-menu-item {
  color: #333;
}

.el-main {
  /deep/.el-tabs__item.is-active {
    background-color: #409eff;
    color: #e9eef3;
  }

  background-color: #e9eef3;
  color: #333;
  margin: 0;
  padding: 0px;
  // text-align: center;
}

.el-container {
  height: 100vh;
}

.menu-icon {
  float: left;
  width: 50px;
  height: 40px;
  background-color: azure;
  margin: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
}

.line {
  position: absolute;

  bottom: 0;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: #fff;
}

.tabs-wrapper {
  outline: 1px solid red;
}

/deed/element.style {
  position: absolute;
  height: 20px;
  display: flex;
  left: 1339px !important;
  margin-bottom: 4px;
  justify-content: flex-start;
}
.el-menu[data-v-94d92748] {
  border: none;
  background-color: #333;
  height: 50px;
}
[v-cloak] .el-tabs__content {
  display: none !important;
}
.el-tabs--border-card > .my-tabs-content {
  padding: 0;
}
.el-tabs__content {
  height: calc(100% - 40px);
}
.s[data-v-94d92748] {
    width: 65px !important;
}


  
</style>

